MV_CC_RegisterImageCallBackForRGB

MV_CC_RegisterImageCallBackForRGB

Register RGB24 image data callback function, supports getting chunk information.

API Definition

int MV_CC_RegisterImageCallBackForRGB(
  void        *handle,
  cbOutput    fOutputCallBack,
  void        *pUser
);

Parameters

handle

[IN] Device handle, which is returned by MV_CC_CreateHandle or MV_CC_CreateHandleWithoutLog.

fOutputCallBack

[IN] RGB24 image data callback function, see the details below:

void(__stdcall* cbOutput)(
  unsigned char           *pData,
  MV_FRAME_OUT_INFO_EX    *pFrameInfo,
  void                    *pUser
);
pData

[OUT] Address of buffer that saves image data

pFrameInfo

[OUT] Obtained information of frame with RGB24 format, including width, height, pixel format, chunk information, and so on. See the structure MV_FRAME_OUT_INFO_EX for details.

pUser

[OUT] User data

pUser

[IN] User data

Return Value

Return MV_OK(0) on success, and return Error Code on failure.

Remarks

  • After calling MV_CC_CreateHandle, call this API to set image data callback function.

  • There are two available image data acquisition modes, and cannot be used together:

    1. Call MV_CC_RegisterImageCallBackForRGB to set RGB24 format image data callback function, and then call MV_CC_StartGrabbing to start acquiring. The acquired image data is returned in the configured callback function.

    2. Call MV_CC_StartGrabbing to start acquiring, and then call MV_CC_GetImageForRGB repeatedly in application layer to get frame data with RGB24 format. When getting frame data, the frequency of calling this API should be controlled by upper layer application according to frame rate.

  • This API is not supported by CameraLink device.

The following sample code is for reference only.

#include "MvCameraControl.h"

void __stdcall ImageCallBack(unsigned char * pData, MV_FRAME_OUT_INFO_EX* pFrameInfo, void* pUser)
{
    if (pFrameInfo)
    {
        // Add the system time when output.
        char   szInfo[128] = {0};
        SYSTEMTIME sys; 
        GetLocalTime( &sys );
        sprintf_s(szInfo, 128, "[%d-%02d-%02d %02d:%02d:%02d:%04d] : GetOneFrame succeed, width[%d], height[%d]", sys.wYear, sys.wMonth,
            sys.wDay, sys.wHour, sys.wMinute, sys.wSecond, sys.wMilliseconds, pFrameInfo->nWidth, pFrameInfo->nHeight);

        printf("%s\n", szInfo);
    }
}

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //Enumerate all the corresponding devices of specified transport protocol in the subnet.
    unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //Selected the first online device in the search result, and create device handle.
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //Register RGB data callback function
    nRet = MV_CC_RegisterImageCallBackForRGB(handle, ImageCallBack, NULL);
    if (MV_OK != nRet)
    {
        printf("error: RegisterImageCallBackForRGB fail [%x]\n", nRet);
        return;
    }

    //Connect to device
    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...Other processes.

    //Start image acquisition
    nRet = MV_CC_StartGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing fail [%x]\n", nRet);
        return;
    }
    
    //...Other processes.


    //Stop image acquisition
    nRet = MV_CC_StopGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StopGrabbing fail [%x]\n", nRet);
        return;
    }

    //Close device, release resource.
    nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //Destroy handle, release resource.
    nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }    
}

MV_CC_RegisterImageCallBackForRGB

Register RGB24 image data callback function, supports getting chunk information.

API Definition

int MV_CC_RegisterImageCallBackForRGB(
  void        *handle,
  cbOutput    fOutputCallBack,
  void        *pUser
);

Parameters

handle

[IN] Device handle, which is returned by MV_CC_CreateHandle or MV_CC_CreateHandleWithoutLog.

fOutputCallBack

[IN] RGB24 image data callback function, see the details below:

void(__stdcall* cbOutput)(
  unsigned char           *pData,
  MV_FRAME_OUT_INFO_EX    *pFrameInfo,
  void                    *pUser
);
pData

[OUT] Address of buffer that saves image data

pFrameInfo

[OUT] Obtained information of frame with RGB24 format, including width, height, pixel format, chunk information, and so on. See the structure MV_FRAME_OUT_INFO_EX for details.

pUser

[OUT] User data

pUser

[IN] User data

Return Value

Return MV_OK(0) on success, and return Error Code on failure.

Remarks

  • After calling MV_CC_CreateHandle, call this API to set image data callback function.

  • There are two available image data acquisition modes, and cannot be used together:

    1. Call MV_CC_RegisterImageCallBackForRGB to set RGB24 format image data callback function, and then call MV_CC_StartGrabbing to start acquiring. The acquired image data is returned in the configured callback function.

    2. Call MV_CC_StartGrabbing to start acquiring, and then call MV_CC_GetImageForRGB repeatedly in application layer to get frame data with RGB24 format. When getting frame data, the frequency of calling this API should be controlled by upper layer application according to frame rate.

  • This API is not supported by CameraLink device.

The following sample code is for reference only.

#include "MvCameraControl.h"

void __stdcall ImageCallBack(unsigned char * pData, MV_FRAME_OUT_INFO_EX* pFrameInfo, void* pUser)
{
    if (pFrameInfo)
    {
        // Add the system time when output.
        char   szInfo[128] = {0};
        SYSTEMTIME sys; 
        GetLocalTime( &sys );
        sprintf_s(szInfo, 128, "[%d-%02d-%02d %02d:%02d:%02d:%04d] : GetOneFrame succeed, width[%d], height[%d]", sys.wYear, sys.wMonth,
            sys.wDay, sys.wHour, sys.wMinute, sys.wSecond, sys.wMilliseconds, pFrameInfo->nWidth, pFrameInfo->nHeight);

        printf("%s\n", szInfo);
    }
}

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //Enumerate all the corresponding devices of specified transport protocol in the subnet.
    unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //Selected the first online device in the search result, and create device handle.
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //Register RGB data callback function
    nRet = MV_CC_RegisterImageCallBackForRGB(handle, ImageCallBack, NULL);
    if (MV_OK != nRet)
    {
        printf("error: RegisterImageCallBackForRGB fail [%x]\n", nRet);
        return;
    }

    //Connect to device
    nRet = MV_CC_OpenDevice(m_handle, nAccessMode, nSwitchoverKey);
    if (MV_OK != nRet)
    {
        printf("error: OpenDevice fail [%x]\n", nRet);
        return;
    }
    //...Other processes.

    //Start image acquisition
    nRet = MV_CC_StartGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StartGrabbing fail [%x]\n", nRet);
        return;
    }
    
    //...Other processes.


    //Stop image acquisition
    nRet = MV_CC_StopGrabbing(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: StopGrabbing fail [%x]\n", nRet);
        return;
    }

    //Close device, release resource.
    nRet = MV_CC_CloseDevice(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: CloseDevice fail [%x]\n", nRet);
        return;
    }

    //Destroy handle, release resource.
    nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }    
}